/**
 * @ Author: luoqi
 * @ Create Time: 2024-07-17 11:39
 * @ Modified by: luoqi
 * @ Modified time: 2024-07-17 22:09
 * @ Description:
 */

#ifndef _RINGBUF_H
#define _RINGBUF_H

#include <stdint.h>

typedef struct 
{
    uint32_t w_index;    // ring buffer w_index index
    uint32_t r_index;    // ring buffer r_index index
    uint32_t msgsz;
    uint32_t bufsz;
    uint8_t  *buf;
} RingBufObj;

int ringbuf_init(RingBufObj *ring, uint8_t *buf, uint32_t size);

int ringbuf_write(RingBufObj *ring, uint8_t *data, uint32_t len);

uint32_t ringbuf_write_covern(RingBufObj *ring, uint8_t *data, uint32_t len);

uint32_t ringbuf_read(RingBufObj *ring, uint8_t *rdata, uint32_t len);

uint32_t ringbuf_get_size(RingBufObj *ring);

void ringbuf_clear(RingBufObj *ring);

#endif
